//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - lower
//===================================================================================


namespace App.Data.SqlServer.Repositories {
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using App.Model;

    public class RecruiterRepository : BaseRepository, IRecruiterRepository {
        public RecruiterRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork) {
        }
        public void Create(Recruiter recruiter) {
            this.GetDbSet<Recruiter>().Add(recruiter);
            this.UnitOfWork.SaveChanges();
        }

        public Recruiter GetRecruiter(Guid recruiterId) {
            return this.GetDbSet<Recruiter>()
                .Where(c => c.Id == recruiterId)
                .Single();
        }

        public Recruiter GetRecruiter(string userName) {
            return this.GetDbSet<Recruiter>()
               .Where(r=>r.UserName == userName)
               .Single();
        }

        public void Update(Recruiter updatedRecruiter) {
            this.GetDbSet<Recruiter>().Attach(updatedRecruiter);
            this.SetEntityState(updatedRecruiter, updatedRecruiter.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid recruiterId) {
            Recruiter RecruiterToDelete = this.GetRecruiter(recruiterId);
            this.GetDbSet<Recruiter>().Remove(RecruiterToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IQueryable<Recruiter> Find()
        {
            return this.GetDbSet<Recruiter>();
        }

        public IQueryable<Recruiter> GetAll()
        {
            return this.GetDbSet<Recruiter>();
        }


        public IQueryable<Recruiter> FindRecruiters()
        {
            throw new NotImplementedException();
        }
    }
}
